﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.SessionState;  
using System.Xml.Linq;

namespace YXShop.Web.filehandle
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class commentform : IHttpHandler, IRequiresSessionState 
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            YXShop.BLL.Accessories.CommentInfo bll = new YXShop.BLL.Accessories.CommentInfo();
            YXShop.Model.Accessories.CommentInfo model = new YXShop.Model.Accessories.CommentInfo();
            model.Type = ChangeHope.WebPage.PageRequest.GetFormString("CommentType") != "" ? int.Parse(ChangeHope.WebPage.PageRequest.GetFormString("CommentType")) : 0; ;
            string Name = string.Empty;
            int UID = 0;
            int isreguser = 0;
            if (context.Session["MemberID"]!=null)
            {
                Name = context.Session["MemberName"].ToString();
                UID = Convert.ToInt32(context.Session["MemberID"].ToString());
                isreguser = 1;
            }
            model.UserName=Name;
            model.UID = UID;
            model.IsReguser = isreguser;
            model.Grade = ChangeHope.WebPage.PageRequest.GetFormString("Rating") == "" ? 5 : int.Parse(ChangeHope.WebPage.PageRequest.GetFormString("Rating"));
            model.Title = ChangeHope.WebPage.PageRequest.GetFormString("txtTitle");
            model.Tag = ChangeHope.WebPage.PageRequest.GetFormString("txtTag");
            YXShop.BLL.Accessories.CommentForm cfbll = new YXShop.BLL.Accessories.CommentForm();
            ChangeHope.DataBase.DataByPage dataPage = cfbll.GetList();
            string Str = string.Empty;
            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    string CommentItemID = dataPage.DataReader["id"].ToString();
                    string CommnetFiled = dataPage.DataReader["filed"].ToString();
                    string StrID=ChangeHope.WebPage.PageRequest.GetFormString("hfCommentItemID" + CommentItemID + "");
                    if (ChangeHope.WebPage.PageRequest.GetFormString("txtCommentItem" + CommentItemID + "") !="")
                    {
                        if (!string.IsNullOrEmpty(Str))
                        {
                            Str += "|br<span style='color:#FF6600'>" + CommnetFiled + "：</span>" + ChangeHope.WebPage.PageRequest.GetFormString("txtCommentItem" + CommentItemID + "");
                        }
                        else
                        {
                            Str = CommnetFiled + "," + ChangeHope.WebPage.PageRequest.GetFormString("txtCommentItem" + CommentItemID + "");
                        }
                    }
                }
            }
            model.ContentList = Str;
            model.CommentTime = System.DateTime.Now;
            model.CommentID = ChangeHope.WebPage.PageRequest.GetFormString("CommentObjectId") != "" ? int.Parse(ChangeHope.WebPage.PageRequest.GetFormString("CommentObjectId")) : 0;
            model.Againstnum = 0;
            model.SupportNum = 0;
            model.FlowerNum = 0;
            if (bll.Add(model) != 0)
            {
                ChangeHope.WebPage.Script.AlertAndGoBack("点评成功,谢谢您的参与.");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
